package com.mp3s.backtest_a.utils;

import java.util.List;

import com.mp3s.interface3.BSData;
import com.mp3s.interface3.BackTestData;
import com.mp3s.interface3.IBT;
import com.mp3s.interface3.QuoteData;
import com.mp3s.interface3.QuoteDataC;
import com.mp3s.interface3.TradeTime;

public class BT implements IBT {

    /*
     * BS返回值：
     * 0，无效
     * 1，buy
     * 2，sell
     */

    public int check(List<BackTestData> btds) {

        //分离出唯一值
        for(BackTestData btd:btds){
            // System.out.println(btd.toString());
        }

        // if(btd.getDirect()==1){
        //     //判断buy是否上涨

        // }else{

        // }

        return 0;
    }


    public static int buy(List<QuoteData> qs,BSData bsd){
            //sign: B
            QuoteData today = qs.get(qs.size()-1);
            QuoteData last = qs.get(qs.size()-2);

            float open = QuoteDataC.open(today, last);
            float close = QuoteDataC.close(today, last);
            float high = QuoteDataC.high(today, last);
            float volume = QuoteDataC.volume(today, last);

			// String template = "[BS Sign][Monitor]-{},stockId:{},cnName:{},up:{}%";
			// String out = StrUtil.format(template, DateTime.now(),today.getName(),today.getCnName(),close);
            // System.out.println(out);

            if(open > bsd.getOpen()){
                //高开过滤
                return 0;
            }         

            if(close > bsd.getClose()){
                //阳线过滤
                return 0;
            }

            if(high > bsd.getHigh()){
                //冲高过滤
                return 0;
            }
            if(volume > bsd.getVolume()){
                //放量过滤
                return 0;
            }

            //不适合买入
            if(false  == TradeTime.isBTime()){
                return 0;
            }

            return 1;
        
    }

    
    public static int sell(List<QuoteData> qs,BSData bsd){
        //sign: B
        QuoteData today = qs.get(qs.size()-1);
        QuoteData last = qs.get(qs.size()-2);

        float open = QuoteDataC.open(today, last);
        if(open < bsd.getOpen()){

        }

        float close = QuoteDataC.close(today, last);
        if(close > bsd.getClose()){
            //阳线冲高，sell
            return 2;
        }

        float high = QuoteDataC.high(today, last);
        if(high > bsd.getHigh()){

        }

        float volume = QuoteDataC.volume(today, last);
        if(volume > bsd.getVolume()){

        }

        return 1;
    
    }


    @Override
    public int BT(List<BackTestData> btds) {
        // TODO Auto-generated method stub
        // throw new UnsupportedOperationException("Unimplemented method 'BT'");
        // for(BackTestData btd:btds){
        //     System.out.println(btd.toString());
        // }

        return check(btds);
    }
}
